package c.c.a;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.text.TextUtils;
import org.json.JSONObject;

public class k extends b2 {
    public final Context e;
    public final g2 f;

    public k(Context context, g2 g2Var) {
        super(false, false);
        this.e = context;
        this.f = g2Var;
    }

    public boolean b(JSONObject jSONObject) {
        int i;
        String packageName = this.e.getPackageName();
        PackageInfo packageInfo = null;
        String str = "package";
        if (TextUtils.isEmpty(this.f.b.getZiJieCloudPkg())) {
            jSONObject.put(str, packageName);
        } else {
            if (m0.b) {
                m0.a("has zijie pkg", null);
            }
            jSONObject.put(str, this.f.b.getZiJieCloudPkg());
            jSONObject.put("real_package_name", packageName);
        }
        try {
            packageInfo = this.e.getPackageManager().getPackageInfo(packageName, 0);
        } catch (Throwable unused) {
        }
        if (packageInfo != null) {
            try {
                i = packageInfo.versionCode;
            } catch (Throwable th) {
                m0.b(th);
                return false;
            }
        }
        i = 0;
        String str2 = "";
        String str3 = "app_version";
        if (TextUtils.isEmpty(this.f.b.getVersion())) {
            jSONObject.put(str3, packageInfo != null ? packageInfo.versionName : str2);
        } else {
            jSONObject.put(str3, this.f.b.getVersion());
        }
        str3 = "app_version_minor";
        if (TextUtils.isEmpty(this.f.b.getVersionMinor())) {
            jSONObject.put(str3, str2);
        } else {
            jSONObject.put(str3, this.f.b.getVersionMinor());
        }
        str2 = "version_code";
        if (this.f.b.getVersionCode() != 0) {
            jSONObject.put(str2, this.f.b.getVersionCode());
        } else {
            jSONObject.put(str2, i);
        }
        str2 = "update_version_code";
        if (this.f.b.getUpdateVersionCode() != 0) {
            jSONObject.put(str2, this.f.b.getUpdateVersionCode());
        } else {
            jSONObject.put(str2, i);
        }
        str2 = "manifest_version_code";
        if (this.f.b.getManifestVersionCode() != 0) {
            jSONObject.put(str2, this.f.b.getManifestVersionCode());
        } else {
            jSONObject.put(str2, i);
        }
        if (!TextUtils.isEmpty(this.f.b.getAppName())) {
            jSONObject.put("app_name", this.f.b.getAppName());
        }
        if (!TextUtils.isEmpty(this.f.b.getTweakedChannel())) {
            jSONObject.put("tweaked_channel", this.f.b.getTweakedChannel());
        }
        if (packageInfo != null) {
            ApplicationInfo applicationInfo = packageInfo.applicationInfo;
            if (applicationInfo != null) {
                i = applicationInfo.labelRes;
                if (i > 0) {
                    jSONObject.put("display_name", this.e.getString(i));
                }
            }
        }
        return true;
    }
}
